package com.lzh.others.basejava.Reflection;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 如何利用反射操作类
 */
public class Main_03 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
        Class<?> aClass1 = Class.forName("com.lzh.others.basejava.Reflection.User");
        Method[] declaredMethods = aClass1.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod.getName());
        }
        Field comments = aClass1.getDeclaredField("comments");
        System.out.println("comments = " + comments.getType());
        System.out.println("comments = " + comments.getGenericType());
        Method myPublicStaticMethod = aClass1.getDeclaredMethod("myPrivateStaticMethod",String.class);
        myPublicStaticMethod.setAccessible(true);
        myPublicStaticMethod.invoke(null,"测试反射填入参数");
    }
}
